package cn.edu.zafu.bigdata.Yum;

import java.io.*;
import java.net.*;
import java.text.SimpleDateFormat; // 导入SimpleDateFormat类
import java.util.Date;

public class Client1 {
    public static void main(String[] args) throws IOException {
        String serverName = "192.168.16.36"; // 服务端地址，可以是IP地址或主机名
        int port = 9876; // 服务端端口号
        byte[] sendData = "What time is it?".getBytes();
        byte[] receiveData = new byte[1024];

        InetAddress IPAddress = InetAddress.getByName(serverName);
        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
        DatagramSocket clientSocket = new DatagramSocket();
        clientSocket.send(sendPacket);

        // 接收服务端响应
        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
        clientSocket.receive(receivePacket);
        String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength());
        System.out.println("Client received: " + sentence);

        clientSocket.close();
    }
}